package host.skiree.nettydemo.server.service.impl;

import host.skiree.nettydemo.message.GroupMembersRequestMessage;
import host.skiree.nettydemo.message.GroupMembersResponseMessage;
import host.skiree.nettydemo.message.Message;
import host.skiree.nettydemo.server.dto.impl.RoomChannelImpl;
import host.skiree.nettydemo.server.service.MessageHandler;
import io.netty.channel.ChannelHandlerContext;

import java.util.Set;

/**
 * @author gcl
 * @date 2022/9/21 8:58
 */
public class GroupMembers implements MessageHandler {
    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        GroupMembersRequestMessage groupChatRequestMessage = (GroupMembersRequestMessage) message;
        String groupName = groupChatRequestMessage.getGroupName();
        if (RoomChannelImpl.ROOM_CHANNEL_MAP.get(groupName) == null){
            ctx.writeAndFlush(new GroupMembersResponseMessage(false,"该聊天室不存在"));
        }else {
            Set<String> names = RoomChannelImpl.ROOM_CHANNEL_MAP.get(groupName);
            ctx.writeAndFlush(new GroupMembersResponseMessage( groupName,names));
        }
    }
}
